
<template>
	<view>
		<view class="list">
			<view v-for="(item,index) in list" :key="index" @click="listItem(item)">
				<view>
					<view>
						<text>{{item.recive_name}}</text>
						<text>{{item.recive_phone}}</text>
					</view>
					<view>
						<text>{{item.recive_city}}</text>
						<text>{{item.recive_address}}</text>
					</view>
				</view>
				<view class="del" @click="del(item.id,index)">
					<image :src="vuex_httpImageUrl && vuex_httpImageUrl+'static/my/deladdress.png'" mode="aspectFill"></image>
				</view>
			</view>
		</view>
		<view class="submit" @click="address">添加地址</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list:[],
				status:''
			};
		},
		onLoad(o) {
			this.status = o.status
		},
		onShow() {
			this.def_list()
		},
		methods:{
			listItem(item){
				if(this.status == 'back'){
					this.$u.vuex('vuex_thisAddress',item)
					uni.navigateBack()
				}
			},
			def_list(){
				this.$u.post('appuser/address_list').then(res=>{
					console.log(res.data);
					this.list = res.data
				})
			},
			del(id,idx){
				uni.showModal({
					title:'提示',
					content:'您确定要删除该条数据吗?',
					success:res=>{
						if(res.confirm){
							this.$u.post('/appuser/del_address',{id}).then(res=>{
								if(res.code == 0){
									this.list.splice(idx,1)
									this.$u.toast('删除成功')
								}
							})
						}
					}
				})
			},
			address(){
				uni.navigateTo({
					url:'./add'
				})
			}
		}
	}
</script>

<style lang="scss">
	.list{
		background-color: #FFFFFF;
		width: 90%;
		margin: 30rpx auto;
		padding: 0 30rpx ;
		>view{
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 30rpx 0;
			border-bottom: 1px solid rgba(0,0,0,.1);
			&:nth-last-child(1){
				border-bottom: 0;
			}
			.del{
				color: red;
				image{
					width: 50rpx;
					height: 50rpx;
				}
			}
		}
	}
	.submit{
		padding: 20rpx 0;
		text-align: center;
	}
</style>
